package com.ludomancy.gamelib;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

public class BarPainter
{
	public static final int HCENTER = 1;
	public static final int BOTTOM = 2;
	
	public static Rectangle paint(Graphics g, Color valueColor, int x, int y, int width, int height, int value, int max)
	{
		return paint(g, valueColor, x, y, width, height, value, max, 0);
	}
	public static Rectangle paint(Graphics g, Color valueColor, int x, int y, int width, int height, int value, int max, int anchor)
    {
        // limit values
        if(value < 0)
        {
            value = 0;
        }
        if(value > max)
        {
            value = max;
        }
        // figure out the limits
        int finalWidth = value*width/max;
        // adjust position
        if((anchor & HCENTER) != 0)
        {
        	x -= width/2;
        }
        if((anchor & BOTTOM) != 0)
        {
        	y -= height;
        }
        
        g.setColor(valueColor);
        g.fillRect(x,y,finalWidth,height);
        return new Rectangle(x, y, finalWidth, height);
    }
}
